home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / skipandgouls.swf / scripts / __Packages / sarbakan / input / KeyBasher.as next >
Text File  |  2007-10-01  |  2KB  |  64 lines

  1. class sarbakan.input.KeyBasher
  2. {
  3.    function KeyBasher(l_nKey, l_nPressNeeded, l_nUpdateDelay, l_fListener)
  4.    {
  5.       mx.transitions.OnEnterFrameBeacon.init();
  6.       this.oEnterFrameListener = new Object();
  7.       this.oEnterFrameListener.onEnterFrame = mx.utils.Delegate.create(this,this.update);
  8.       MovieClip.addListener(this.oEnterFrameListener);
  9.       this.oKey = sarbakan.input.KeyManager.getInstance();
  10.       this.oKey.addKeyListener(l_nKey,"KEY");
  11.       this.nPressNeeded = l_nPressNeeded;
  12.       this.nPressCount = 0;
  13.       this.nUpdateDelay = l_nUpdateDelay;
  14.       this.nUpdateCount = 0;
  15.       this.fListener = l_fListener;
  16.       this.bLastFrameWasDown = false;
  17.       this.bAutoBashing = false;
  18.    }
  19.    function enableAutoBashing()
  20.    {
  21.       this.bAutoBashing = true;
  22.    }
  23.    function disableAutoBashing()
  24.    {
  25.       this.bAutoBashing = false;
  26.    }
  27.    function end()
  28.    {
  29.       MovieClip.removeListener(this.oEnterFrameListener);
  30.    }
  31.    function update()
  32.    {
  33.       if(this.oKey.KEY)
  34.       {
  35.          if(!this.bLastFrameWasDown)
  36.          {
  37.             this.nPressCount = this.nPressCount + 1;
  38.          }
  39.          this.bLastFrameWasDown = true;
  40.       }
  41.       else
  42.       {
  43.          this.bLastFrameWasDown = false;
  44.       }
  45.       if(++this.nUpdateCount == this.nUpdateDelay)
  46.       {
  47.          this.report();
  48.          this.nUpdateCount = 0;
  49.          this.nPressCount = 0;
  50.       }
  51.    }
  52.    function report()
  53.    {
  54.       if(this.nPressCount >= this.nPressNeeded || this.bAutoBashing)
  55.       {
  56.          this.fListener(true);
  57.       }
  58.       else
  59.       {
  60.          this.fListener(false);
  61.       }
  62.    }
  63. }
  64.